import { ImgUploadComponent } from './../img-upload/img-upload.component';
import { Component, OnInit, Input, Output, EventEmitter, ViewChild } from '@angular/core'
import { Toast } from 'ng-zorro-antd-mobile';

@Component({
    selector: 'cp-estate-review',
    templateUrl: './estate-review-component.html',
    styleUrls: ['./estate-review-component.scss'],
    providers: [Toast]
})
export class EstateReviewComponent implements OnInit {

    public checkItemData = { value: 0, name: 'select', checked: false }
    public textarea = "";

    @ViewChild(ImgUploadComponent)
    private imgUpload: ImgUploadComponent;


    @Input() title;
    @Input() _show = false
    @Input()
    get show() {
        return this._show
    }
    set show(value) {
        this._show = value
        this.showChange.emit(value)
    }

    @Output() showChange = new EventEmitter()

    @Output() release = new EventEmitter();

    constructor(
        private _toast: Toast,
    ) { }

    ngOnInit() {

        // console.log(this.imgUpload);

    }

    onChange = (val: any) => {
        console.log('onChange Event: ', val);
    }
    cancel() {

        this.show = false;
    }
    _release() {

        if(this.imgUpload.isUpdate){

            this.imgUpload.uploadImg(res => {
                console.log(res);
                this.releaseMt(res)
            },(error)=>{
                Toast.fail('图片上传异常')
            });
        }else{
            this.releaseMt()
        }

    }

    private releaseMt(res?){
        
        let data = {
            textarea: this.textarea,
            checked: this.checkItemData.checked,
            photo: res
        }
        this.release.emit(data);
    }
}
